package cn.iocoder.yudao.module.alipay.controller.app.infoproduction;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
import cn.iocoder.yudao.module.alipay.controller.admin.infoproduction.vo.*;
import cn.iocoder.yudao.module.alipay.convert.infoproduction.InfoProductionConvert;
import cn.iocoder.yudao.module.alipay.dal.dataobject.infoproduction.InfoProductionDO;
import cn.iocoder.yudao.module.alipay.service.infoproduction.InfoProductionService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.io.IOException;
import java.util.Collection;
import java.util.List;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT;

@Tag(name = "小程序app - 作品")
@RestController
@RequestMapping("/alipay/info-production")
@Validated
public class InfoProductionAppController {

    @Resource
    private InfoProductionService infoProductionService;

    @GetMapping("/get")
    @Operation(summary = "获得作品")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    public CommonResult<InfoProductionRespVO> getInfoProduction(@RequestParam("id") Long id) {
        InfoProductionDO infoProduction = infoProductionService.getInfoProduction(id);
        return success(InfoProductionConvert.INSTANCE.convert(infoProduction));
    }


    @GetMapping("/getListByTypeId")
    @Operation(summary = "根据分类id获取作品集")
    public CommonResult<List<InfoProductionRespVO>> getListByTypeId(String typeId) {
        List<InfoProductionDO> list = infoProductionService.getListByTypeId(typeId);
        return success(InfoProductionConvert.INSTANCE.convertList(list));
    }

    @PostMapping("/page")
    @Operation(summary = "获得作品分页")
    public CommonResult<PageResult<InfoProductionRespVO>> getInfoProductionPage(@RequestBody InfoProductionPageReqVO pageVO) {
        PageResult<InfoProductionDO> pageResult = infoProductionService.getInfoProductionPage(pageVO);
        return success(InfoProductionConvert.INSTANCE.convertPage(pageResult));
    }


}
